#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2e5 + 10;

int n, w[N];
vec G[N];
int f[N], g[N];

int cnt(int id, int x) { return (id - 1) / w[x] + 1; }

int pot[N], top;
int pmx[N], smx[N], ans[N];

void dfs(int x, int p) {
	for(auto y : G[x]) if(y ^ p) dfs(y, x);
	top = 0; for(auto y : G[x]) if(y ^ p) pot[++top] = f[y];
	sort(pot + 1, pot + top + 1, greater < int > ());
	rep(i, 1, top) chkmax(f[x], pot[i] + cnt(i, x));
}

void rdfs(int x, int p) {
	top = 0; for(auto y : G[x]) pot[++top] = y;
	f[p] = g[x]; sort(pot + 1, pot + top + 1, [](auto a, auto b) { return f[a] > f[b]; });
	pmx[0] = -1e9; smx[top + 1] = -1e9;
	rep(i, 1, top) pmx[i] = max(pmx[i - 1], f[pot[i]] + cnt(i, x));
	per(i, top, 1) smx[i] = max(smx[i + 1], f[pot[i]] + cnt(i - 1, x));
	ans[x] = pmx[top];
	//cerr << ans[x] << " " << f[x] << " " << g[x] << " " << top << " " << x << endl;
	rep(i, 1, top) if(pot[i] ^ p) g[pot[i]] = max(0, max(pmx[i - 1], smx[i + 1]));
	for(auto y : G[x]) if(y ^ p) rdfs(y, x);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; rep(i, 1, n) w[i] = in;
	rep(i, 1, n - 1) { int u = in, v = in; G[u].eb(v); G[v].eb(u); }
	dfs(1, 0); g[1] = -1e9; rdfs(1, 0); rep(i, 1, n) printf("%d\n", max(ans[i], 0));
	return 0;
}
